package com.trkj.usercenter.feedback;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.trkj.base.BaseBackFragmentActivity;
import com.trkj.base.Constants;
import com.trkj.taoruiyun.R;

/**
 * Created by LiZanhong on 2015/06/25.
 */
public class FeedbackActivity extends BaseBackFragmentActivity{
    public static final String ACTION = "com.trkj.usercenter.feedback.FeedbackActivity";
    private FeedbackFragment feedbackFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentFragment(feedbackFragment = new FeedbackFragment());
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.fragment_attach);
    }


    @Override
    public String getCustomerTitle() {
        return "反馈意见";
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuItem menuAdd = menu.add(Menu.NONE, Constants.MenuID.MENU_ADD_FEEDBACK, Menu.NONE, "反馈");
        menuAdd.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        //打开反馈窗口
        if(item.getItemId() == Constants.MenuID.MENU_ADD_FEEDBACK){
            Intent intent = new Intent(FeedbackAddActivity.ACTION);
            startActivityForResult(intent, Constants.ActivityCode.FEEDBACK_ADD_REQUEST_CODE);
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if(requestCode == Constants.ActivityCode.FEEDBACK_ADD_REQUEST_CODE
                && resultCode == Activity.RESULT_OK
                && data.getExtras().getBoolean("success")){
            feedbackFragment.refreshData();
        }
    }
}
